<?php
	class Admin_Model extends CI_Model {
		function __construct()
		{
			parent::__construct();	
		}
		
		function addUser($user)
		{
			if($user['username'] != null) {
				$this->load->helper('security');
				$data = array(
					'username' => $user['username'] ,
					'password' => dohash($user['password']) ,
					'profile' => $user['profile'],
					'is_active' => 1
				);
				$this->db->set('create_by', "'". $this->session->userdata('username') ."'", FALSE);
				$this->db->set('create_date', 'NOW()', FALSE); 
				$this->db->insert('admin', $data);
			} 
		}
		
		function updateUser($user)
		{
			$this->load->helper('security');
			if($user['username'] != null) {
				$data = array(
					'password' => dohash($user['password']) ,
					'update_by' => $this->session->userdata('username')
				);
				$this->db->set('update_date', 'NOW()', FALSE); 
				$this->db->where('username', $user['username']);
				$this->db->update('admin', $data);
			} 
		}
		
		function deleteUser($user)
		{
			$this->db->where('username', $user); 
			$this->db->delete('admin'); 
		}
		
		function getUserByUsername($user)
		{
			$query = $this->db->get_where('admin', array('username' => $user));
			return $query->row_array();
		}
	}


/* End of file admin_model.php */
/* Location: ./application/models/admin/admin_model.php */